package tcpserver;

import frame.laxcen.BaseFrame;
import io.netty.channel.Channel;

import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;

public class RFIDSession {

    private ArrayBlockingQueue<BaseFrame> queue = new ArrayBlockingQueue<>(1024);

    private LinkedList<BaseFrame> overflow = new LinkedList<>();

    private Channel channel;

    public RFIDSession(Channel channel) {

        this.channel = channel;
    }

    public void clear() {

        overflow.clear();

        queue.clear();
    }

    public ArrayBlockingQueue<BaseFrame> getQueue() {

        return queue;
    }

    public Channel getChannel() {

        return channel;
    }

    public List<BaseFrame> getOverflow() {

        return overflow;
    }

    @Override
    public boolean equals(Object o) {

        if(this == o) return true;

        if(o == null || getClass() != o.getClass()) return false;

        RFIDSession that = (RFIDSession) o;

        return channel != null ? channel.id().asLongText().equals(that.channel.id().asLongText()) : that.channel == null;
    }

    @Override
    public int hashCode() {

        return channel != null ? channel.id().asLongText().hashCode(): 0;
    }
}
